package com.flismax.mysms.activity.sms;



import java.util.ArrayList;

import com.flismax.mysms.R;
import com.flismax.mysms.activity.sms.QuanLySMS.SMSHolder;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class QuanLyContact extends Activity{
	ArrayList<String> model=new ArrayList<String>();
	ContactAdapter adapter=null;
	@SuppressWarnings("unused")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.listcontact);
		//ListView list=(ListView)findViewById(R.id.listsmsquanly);
	    //adapter=new ContactAdapter();
	    //list.setAdapter(adapter);
		/*TextView t=(TextView)findViewById(R.id.t1);
		model=getNames();
		for (int i=0;i<model.size();i++){
			String tt=model.get(i).toString();
			t.setText(tt);
			break;
		}*/
	}
	public ArrayList<String> getNames(){
		ArrayList<String> arr=new ArrayList<String>();
		@SuppressWarnings("deprecation")
		String NAME=android.provider.Contacts.People.NAME;
		Uri uri = Uri.parse("content://contacts/people");
		Cursor rs=getContentResolver().query(uri,null,null,null,null);
		int nameIndex=rs.getColumnIndex(NAME);
		String name="";
		while (rs.moveToNext()){
				name+=rs.getString(nameIndex)+" ";		
		}
		arr.add(name);
		return arr;
	}
	 public boolean onCreateOptionsMenu(Menu menu) {
		    new MenuInflater(this).inflate(R.menu.optioncontact, menu);

		    return(super.onCreateOptionsMenu(menu));
		  }
	 @Override
	  public boolean onOptionsItemSelected(MenuItem item) {
	    if (item.getItemId()==R.id.addcontact) {
	      String message="selected add Contact";
	      Toast.makeText(this, message, Toast.LENGTH_LONG).show();
	      Intent i = new Intent(this, AddContact.class);
          startActivity(i);
	      return(true);
	    }
	    else if (item.getItemId()==R.id.editContact) {
	    	 String message="selected Edit Contact";
		      Toast.makeText(this, message, Toast.LENGTH_LONG).show();
	      
	      return(true);
	    }
	    else if (item.getItemId()==R.id.searchContact) {
	    	 String message="selected Search Contact";
		      Toast.makeText(this, message, Toast.LENGTH_LONG).show(); 
		      
		      return(true);
		    }
	    
	    return(super.onOptionsItemSelected(item));
	  }
	class ContactAdapter extends ArrayAdapter<String> {
		ContactAdapter() {
			super(QuanLyContact.this, R.layout.row, model);
		}
		public View getView(int position, View convertView,
                     ViewGroup parent) {
			View row=convertView;
			SMSHolder holder=null;
   
			if (row==null) {                          
				LayoutInflater inflater=getLayoutInflater();
				row=inflater.inflate(R.layout.row, parent, false);
				holder=new SMSHolder(row);
				row.setTag(holder);
			}
			else {
				holder=(SMSHolder)row.getTag();
			}
			return(row);
		}
	}

}
